package com.qk.management.controller;

import com.qk.common.PageResult;
import com.qk.common.Result;
import com.qk.dto.course.CourseDTO;
import com.qk.entity.Course;
import com.qk.management.service.CourseService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * &#064;author：zzq
 * &#064;createTime：2025/10/09 09:49
 * &#064;description： 
 */
@RestController
@RequestMapping("/courses")
@Slf4j
public class CourseController {
    @Autowired
    private CourseService courseService;
    //根据学科查询课程
    @GetMapping("/subject/{subject}")
    public Result listBySubject(@PathVariable String subject) {
        log.info("根据学科查询课程信息，参数：{}", subject);
        List<Course> courseList = courseService.listBySubject(subject);
        return Result.success(courseList);
    }
    //查询所有课程
    @GetMapping("/list")
    public Result list() {
        log.info("查询所有课程信息");
        List<Course> courseList = courseService.list();
        return Result.success(courseList);
    }
    //修改课程
    @PutMapping
    public Result update(@RequestBody Course course) {
        log.info("修改课程信息，参数：{}", course);
        courseService.update(course);
        return Result.success();
    }

    //根据id查询
    @GetMapping("/{id}")
    public Result get(@PathVariable Integer id) {
        log.info("查询课程，参数：{}", id);
        Course course = courseService.get(id);
        return Result.success(course);
    }

    //根据id删除
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id) {
        log.info("删除课程，参数：{}", id);
        courseService.removeById(id);
        return Result.success();
    }

    //添加课程
    @PostMapping
    public Result addCourse(@RequestBody Course course) {
        log.info("添加课程信息，参数：{}", course);
        courseService.addCourse(course);
        return Result.success();
    }

    @GetMapping
    public Result list(CourseDTO dto) {
        PageResult<Course> pageResult = courseService.list(dto);
        return Result.success(pageResult);
    }
}
